<template>
	<view class="register">
		<view class="register-header">
			<view class="hello">你好!</view>
			<view class="welcome">欢迎你来加入我们</view>
		</view>

		<view class="register-form">
			<view class="username-form">
				<view class="username-title">账号</view>
				<view class="detale-icon" v-if="username!=''"  @click="username=''"></view>
				<input type="text" class="username" v-model="username" />
				<view class="error" v-if="isError">
					<view class="error-icon"></view>
					<view class="error-text">无效的账号</view>
				</view>
			</view>
			<view class="password-form">
				<view class="password-icon" :class="isShow==true?'active':''" @click="isShow = !isShow"></view>
				<view class="password-titile">密码</view>
				<input :type="isShow?'text':'password'" class="password" v-model="password" />
			</view>
			<view class="register-func">
				<view class="func-left">
					<!-- <uni-data-checkbox multiple v-model="value" :localdata="range" @change="change"></uni-data-checkbox> -->
					<!-- <view class="remember">记住我</view> -->
				</view>
			</view>
			<view class="submit-butt">
				<view class="submit" @click="userRegister">注册</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { register } from "@/api/request"
	export default {
		data() {
			return {
				username:"15733333333",
				password:"123456",
				isShow:false,
				isError:false,
				value: 0,
				range:[{'value':0,"text":"记住我"}]
			}
		},
		methods: {
			userRegister(){
				if(this.username==""){
					uni.showToast({
						title:"请输入注册账号",
						icon:"none"
					})
					return
				}
				if(this.password==""){
					uni.showToast({
						title:"请输入密码",
						icon:"none"
					})
					return
				}
				let data = {
					user_acc:this.username,
					user_pwd:this.password
				};
				register(data).then(content=>{
					console.log(content);
					// let { code,data } = content
					if(content.code==200){
						uni.showToast({
							title:"注册成功,跳转到登录",
							icon:"none"
						})
						uni.navigateTo({
							url:"/pages/login/login"
						})
					}
				}).catch(err=>{
					console.log(err);
				})
			},
			change(e) {
				console.log('e:', e);
			}
		}
	}
</script>

<style lang="scss" scoped>
	.register {
		width: 100%;
		padding: $uni-box-padding;
	}

	.register-header {
		padding-bottom: 60rpx;

		.hello {
			font-size: 96rpx;
			color: #5890FF;
			font-weight: bold;
		}

		.welcome {
			padding-top: 30rpx;
			font-size: 40rpx;
			color: #4E4B66;
		}
	}

	.register-form {
		width: 100%;
		padding: 30rpx 0;
		
		
		.password-form,
		.username-form {
			padding-bottom: 45rpx;

			.password-titile,
			.username-title {
				font-size: 32rpx;
				color: #4E4B66;
				padding-bottom: 10rpx;
			}

			.password,
			.username {
				width: 100%;
				height: 76rpx;
				line-height: 76rpx;
				border: 1px solid #4E4B66;
				box-sizing: border-box;
				padding: 0 20rpx;
				border-radius: 10rpx;
				outline: 0;
			}
		}
		.username-form{
			position: relative;
			.detale-icon{
				z-index: 1;
				position: absolute;
				top: 70rpx;
				right: 10rpx;
				width: 48rpx;
				height: 48rpx;
				background-image: url("@/static/image/detele.png");
				background-repeat: no-repeat;
				background-size: 100%;
			}
			.error{
				position: absolute;
				bottom: 10rpx;
				left: 0;
				display: flex;
				align-items: center;
				.error-icon{
					width: 26rpx;
					height: 26rpx;
					background-image: url("@/static/image/error.png");
					background-repeat: no-repeat;
					background-size: 100%;
				}
				.error-text{
					font-size: 20rpx;
					color: red;
				}
			}
		}
		.password-form{
			position: relative;
			padding-bottom: 10rpx;
			.password-icon{
				z-index: 1;
				position: absolute;
				top: 70rpx;
				right: 10rpx;
				width: 48rpx;
				height: 48rpx;
				background-image: url("@/static/image/notlook.png");
				background-repeat: no-repeat;
				background-size: 100%;
				
				&.active{
					background-image: url("@/static/image/look.png");
				}
			}
		}
	
		.submit-butt{
			padding-top: 30rpx;
			text-align: center;
			.submit{
				padding: 15rpx 0;
				margin: 0 auto;
				// width: 70%;
				background-color: #5890FF;
				border-radius: 10rpx;
				color: #fff;
			}
		}
	}
</style>